/**
 * $Revision: 1.0 $
 * $Author: Eric Yang $
 * $Date: Apr 17, 2009 8:19:31 PM $
 *
 * Author: Eric Yang
 * Date  : Apr 17, 2009 8:19:31 PM
 *
 */
package com.hgy.commonsale.webui.conf;

import java.io.IOException;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.geln.util.ClassUtil;

/**
 * @author Eric Yang
 * @version 1.0 <br>
 *          This is the webapp configuration class.<br>
 *          you can't get you configuration in the file "ApplicationResource.properties" from this class.<br>
 *          eg: UPLOAD_DIR="/upload/"
 */
public class ApplicationConfiguration {

	private static final String APPLICATION_FILE_NAME = "ApplicationResources.properties";

	private static Log logger = LogFactory.getLog(ApplicationConfiguration.class);

	public static final String UPLOAD_DIR_KEY = "upload.dir";

	public static String UPLOAD_DIR;

	private static Properties properties;

	static {
		properties = new Properties();
		try {
			properties.load(ClassUtil.getConfigureAsStream(APPLICATION_FILE_NAME));
		} catch (IOException e) {
			e.printStackTrace();
			logger.error(e.getMessage(), e);
		}
	}

	private ApplicationConfiguration() {
	}

	public static String getProperty(String key) {
		if (key != null && key.trim().length() != 0)
			return properties.getProperty(key);
		return null;
	}

	public static void setProperty(String key, String value) {
		if (key != null && key.trim().length() != 0 && value != null && value.trim().length() != 0)
			properties.setProperty(key, value);
	}
}
